package com.hahaliu.hahaliu.controller.user;


import com.hahaliu.hahaliu.common.context.CurrentUser;
import com.hahaliu.hahaliu.common.result.Result;
import com.hahaliu.hahaliu.service.message.ChatDetailedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user/chat-detail")
@Api(tags = "用户端聊天详情相关接口")
@Slf4j
public class ChatDetailedController {
    @Autowired
    private ChatDetailedService chatDetailedService;

    @Autowired
    private CurrentUser currentUser;

    @GetMapping("/get-more")
    @ApiOperation("获取更多历史消息记录")
    public Result<Map<String, Object>> getMoreChatDetails(@RequestParam("uid") Integer uid,
                                                          @RequestParam("offset") Long offset) {
        Integer loginUid = currentUser.getUserId();
        return Result.success(chatDetailedService.getDetails(uid, loginUid, offset));
    }

    @PostMapping("/delete")
    @ApiOperation("删除消息")
    public Result delDetail(@RequestParam("id") Integer id) {
        Integer loginUid = currentUser.getUserId();
        chatDetailedService.deleteDetail(id, loginUid);
        return Result.success();
    }
}
